package com.example.administrator.daggerdemo.base2.base;


import com.example.administrator.daggerdemo.module.NetWorkManager;

import rx.Subscription;
import rx.subscriptions.CompositeSubscription;

/**
 * 代理对象的基础实现
 *
 * @param <T> 视图接口对象(view) 具体业务各自继承自IBaseView
 */
public class BasePresenterImpl<T extends IBaseView> implements IBasePresenter {
    public T iView;
    public NetWorkManager netWorkManger;
    /**
     * 构造方法
     *
     * @param view 具体业务的接口对象
     */
    public BasePresenterImpl(T view) {
        this.iView = view;
        onResume();
    }



    @Override
    public void onResume() {
        netWorkManger= NetWorkManager.getInstance();
    }

    @Override
    public void onDestroy() {
// TODO: 16/8/17 find when unsubcrible
        if (this.mCompositeSubscription != null) {
            this.mCompositeSubscription.unsubscribe();
        }
    }

    private CompositeSubscription mCompositeSubscription;

    protected void addSubscription(Subscription s) {
        if (this.mCompositeSubscription == null) {
            this.mCompositeSubscription = new CompositeSubscription();
        }
        this.mCompositeSubscription.add(s);
    }
}
